<template>
  <div ref="vantaRef" style="width: 100%; height: 100vh">
    <div class="center">
      <div class="logon">
        <div class="overlaylong">
          <div class="overlaylong-Signin">
            <el-form :model="userInfo" :rules="rules" ref="userInfo" label-width="100px">
              <el-form-item label="昵 称:" prop="nick_name">
                <el-input style="width: 200px" size="mini" v-model="userInfo.nick_name"> </el-input>
              </el-form-item>
              <el-form-item label="用 户 名:" prop="username">
                <el-input style="width: 200px" size="mini" v-model="userInfo.username"> </el-input>
              </el-form-item>
              <el-form-item label="密 码:" prop="password">
                <el-input style="width: 200px" size="mini" v-model="userInfo.password"> </el-input>
              </el-form-item>
              <el-form-item label="确 认 密 码" prop="re_password">
                <el-input style="width: 200px" size="mini" v-model="userInfo.re_password"> </el-input>
              </el-form-item>
              <el-form-item label="验 证 码:" prop="check_code">
                <div class="btns">
                  <el-input style="width: 80px" size="mini" v-model="userInfo.check_code"> </el-input>
                  <el-image style="width: 150px; height: 40px;" :src="checkImg.b64s" fit="contain"
                    @click="getCheckUrl"></el-image>
                </div>
              </el-form-item>
            </el-form>
          </div>
        </div>
        <div class="overlaytitle">
          <div class="overlaytitle-Signin">
            <h2 class="overlaytitleH2">Hello,Friend!</h2>
            <p class="overlaytitleP">
              Enter your personal details and start journey with us
            </p>
            <button class="inupbutton" @click="registerUser">注 册</button>
            <button class="inupbutton" @click="toWelcome" style="  background-color: #4284db;">返 回</button>
          </div>
        </div>
      </div>

    </div>
  </div>
</template>

<script>
import * as THREE from 'three'//导入样式
import BIRDS from 'vanta/src/vanta.fog'//导入动态样式逻辑
export default {
  name: 'register',
  data() {
    return {
      //验证码
      checkImg: {
        b64s: "",
        search_id: "",
      },
      userInfo: {
        nick_name: "",
        username: "",
        password: "",
        re_password: "",
        search_id: "",
        check_code: "",
      },
      // 表单数据验证规则
      rules: {
        nick_name: [
          { required: true, message: "╭(°A°`)╮ 请输入用户昵称:", trigger: "blur" },
          {
            min: 2,
            max: 25,
            message: "长度在 2 到 25 个字符",
            trigger: "blur",
          },
        ],
        username: [
          { required: true, message: "(*・_・)ノ 请输入用户名:", trigger: "blur" },
          {
            min: 2,
            max: 25,
            message: "长度在 2 到 25 个字符",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "→_→ 请输入密码:", trigger: "blur" },
          { min: 6, max: 15, message: "长度在 6到 15 个字符", trigger: "blur" },
        ],
        re_password: [
          { required: true, message: "→_→ 请输入密码:", trigger: "blur" },
          { min: 6, max: 15, message: "长度在 6到 15 个字符", trigger: "blur" },
        ],
        check_code: [
          { required: true, message: "(°ー°〃)请输入验证码:", trigger: "blur" },
        ],
      },
    }
  },
  methods: {
    //获得验证码
    async getCheckUrl() {
      const resp = await this.$axios.get("/common/checkImg")
      this.checkImg = resp.data.data
      this.userInfo.search_id = this.checkImg.search_id
    },
    registerUser() {
      let that = this
      this.$refs.userInfo.validate(async (result) => {
        if (!result) return;
        const Data = { ...this.userInfo };
        // console.log(loginData)
        that.$axios.post("/user/register", Data).then((res) => {
          let result = res.data
          if (result.code === 1000) {
            this.$message({
              message: '注册成功',
              type: 'success'
            });
            that.$router.push("/")
            return
          } else {
            this.$message.error(result.msg);
          }
        })
      });
    },
    toWelcome() {
      this.$router.push("/login")
    }
  },
  mounted() {
    this.vantaEffect = BIRDS({
      el: this.$refs.vantaRef,
      THREE: THREE
    })
    // 修改颜色时 cells 需要全大写字母 可生效
    VANTA.FOG({
      el: this.$refs.vantaRef,
      mouseControls: true,
      touchControls: true,
      gyroControls: false,
      minHeight: 200.00,
      minWidth: 200.00,
      highlightColor: 0xc5ff,
      midtoneColor: 0x3eff,
      lowlightColor: 0x0,
      baseColor: 0xffffff
    });
  },
  beforeDestroy() {
    if (this.vantaEffect) {
      this.vantaEffect.destroy()
    }
  },
  created() {
    this.getCheckUrl()
  }
}
</script>
<style>
.center {
  width: 100%;
  height: 100vh;
  /*background-image: url('https://gd-hbimg.huaban.com/9165dc3c0f8279ae5402d1f47212847bff68b49f3cb547-QEli8R');*/
  background-size: 100% 100%;
  background-repeat: no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

h1 {
  font-size: 30px;
  color: black;
}

.logon {
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
  /* position: relative;
  overflow: hidden; */
  width: 768px;
  max-width: 100%;
  min-height: 480px;
  margin-top: 20px;
  display: flex;
  background: -webkit-linear-gradient(right, #4284db, #29eac4);
}

.overlaylong {
  border-radius: 10px 0 0 10px;
  width: 50%;
  height: 100%;
  background-color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlaylongleft {
  border-radius: 0px 10px 10px 0px;
  width: 50%;
  height: 100%;
  background-color: #fff;
  transform: translateX(100%);
  transition: transform 0.6s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlaylongright {
  border-radius: 10px 0 0 10px;
  width: 50%;
  height: 100%;
  background-color: #fff;
  transform: translateX(0%);
  transition: transform 0.6s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlaytitle {
  border-radius: 0px 10px 10px 0px;
  width: 50%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0);
  display: flex;
  align-items: center;
  justify-content: center;
}


.overlaytitleH2 {
  font-size: 30px;
  color: #fff;
  margin-top: 20px;
}

.overlaytitleP {
  font-size: 15px;
  color: #fff;
  margin-top: 20px;
}

.overlaytitleleft {
  border-radius: 0px 10px 10px 0px;
  width: 50%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateX(0%);
  transition: transform 0.6s ease-in-out;
}

.overlaytitleright {
  border-radius: 0px 10px 10px 0px;
  width: 50%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateX(-100%);
  transition: transform 0.6s ease-in-out;
}

.overlaytitle-Signin {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.overlaytitle-Signup {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.buttongohs {
  width: 180px;
  height: 40px;
  border-radius: 50px;
  border: 1px solid #fff;
  color: #fff;
  font-size: 15px;
  text-align: center;
  line-height: 40px;
  margin-top: 40px;
}

.overlaylongH2 {
  font-size: 25px;
  color: black;
  /* width: 250px; */
}

.overlaylong-Signin {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.overlaylong-Signup {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

input {
  background-color: #eee;
  border: none;
  padding: 12px 15px;
  margin: 10px 0;
  width: 240px;
}

h3 {
  font-size: 10px;
  margin-top: 10px;
  cursor: pointer;
}

.inupbutton {
  background-color: #29eac4;
  border: none;
  width: 180px;
  height: 40px;
  border-radius: 50px;
  font-size: 15px;
  color: #fff;
  text-align: center;
  line-height: 40px;
  margin-top: 30px;
}

/*---*/
.btns {
  display: flex;
  justify-content: center;
  background-color: #fff;
}
</style>